<?php

namespace App\Models\Webserver;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Webserver\ShopItem
 *
 * @property int $id
 * @property int $id_sub_category
 * @property string $id_item
 * @property string $name
 * @property int $price
 * @property int $quantity
 * @property int $level
 * @property int $purchased
 * @property string $quality_item
 * @property int $preview
 * @property-read \App\Models\Webserver\ShopSubCategory $sub
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereIdItem($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereIdSubCategory($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem wherePreview($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem wherePurchased($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereQualityItem($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem whereQuantity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Webserver\ShopItem withCategory()
 * @mixin \Eloquent
 */
class ShopItem extends Model {

    protected $table        = 'shop_items';
    protected $connection   = 'webserver';
    protected $fillable     = ['id_item', 'quality_item', 'id_sub_category', 'name', 'price', 'quantity', 'level', 'preview'];
    public $timestamps      = false;

    public function sub()
    {
      return $this->belongsTo('App\Models\Webserver\ShopSubCategory', 'id_sub_category', 'id');
    }

    public function scopeWithCategory($query)
    {
      return $query->with(['sub' => function($query) {
        return $query->with('category');
      }]);
    }

}
